package mysql

import (
	"gorm.io/gorm"
)

type House struct {
	gorm.Model
	UserId      int64  `gorm:"type:int(11);not null;comment:用户id"`
	HouseName   string `gorm:"type:varchar(20);not null;comment:房源名称"`
	Price       int64  `gorm:"type:int;comment:价格"`
	Floor       int64  `gorm:"type:int(11);comment:楼层"`
	Area        int64  `gorm:"type:int(11);comment:面积"`
	Cover       string `gorm:"type:varchar(200);comment:图片"`
	Address     string `gorm:"type:varchar(100);comment:地址"`
	Describe    string `gorm:"type:varchar(150);comment:描述"`
	HouseStatus int64  `gorm:"type:tinyint(1);default:1;comment:状态:待出售1:,2:上架:,3:下架"`
}

func (h *House) Create() error {
	return Db.Create(&h).Error
}
func (h *House) HouseInfo(houseId int64) error {
	return Db.Where("id = ?", houseId).Limit(1).Find(&h).Error
}
func (h *House) HouseList(starPrice, endPrice int) (HouseList []*House, err error) {
	db := Db.Debug()
	if starPrice > 0 {
		db = db.Where("price >=?", starPrice)
	}
	if endPrice > 0 {
		db = db.Where("price <=?", endPrice)
	}
	err = Db.Order("house_status desc").Limit(10).Find(&HouseList).Error
	return
}
